<?php 	include("head.php");

		include_once("paging_function.php");

?>

<?php

/////////////////////////////////PAGING /////////////////

 	if(isset($_GET['page']) && $_GET['page']!='')

		{
			$page = $_GET['page'];
		}
	else
		{
			$page = 0;
		}

$limit=$adminpagelimit;

/////////////////////////////////////////////////////////////////	

?>

<?php

////////////////////////////////////////////    Block_---- DELETE  ///////////

if(isset($_POST['Submit']))

{

	$del=$_POST['del'];
	$no=count($del);
	if($no>0)
	{
	for($i=0;$i<$no;$i++)
	{

	  mysql_query("DELETE FROM ".SITEUSERS." WHERE siteuserId= '".$del[$i]."' ");	   

	}
	echo '<script>window.location="advatisor.php?dlt=1"</script>';
	}


}

////////////////////////////////////////

?><script>
function changeUrl(indexalpha)
{
var url='advatisor.php?index='+indexalpha;
window.location=url;
}
function closeEditWin()
{
document.getElementById('editWin').style.display='none';
}

</script>
<?php
$statustype=$_POST['selectstatus'];
$searchSql.="SELECT * FROM ".SITEUSERS." WHERE userType='A'";
$TEMP_hold=0;
	if(isset($_POST['user']) && $_POST['user']!="")

	{
		$searchSql.=" and username LIKE '".$_POST['user']."%'";
		$TEMP_hold=1;
	}
	if(isset($_POST['email']) && $_POST['email']!="")

	{

		$searchSql.=" and email LIKE '".$_POST['email']."%'";
		$TEMP_hold=1;
	}
//-----------------------------------------status-----------------------------------------
	if(isset($_POST['selectstatus']) && $_POST['selectstatus'] =='Y')

	{

		$searchSql.=" and status ='Y'";
		$TEMP_hold=1;
	}
	if(isset($_POST['selectstatus']) && $_POST['selectstatus']=='N')

	{

		$searchSql.=" and status = 'N'";
		$TEMP_hold=1;
	}
	if(isset($_POST['selectstatus']) && $_POST['selectstatus']=='P')

	{

		$searchSql.=" and status ='P'";
		$TEMP_hold=1;
	}
		if(isset($_POST['selectstatus']) && $_POST['selectstatus']=='B')

	{

		$searchSql.=" and status ='B'";
		$TEMP_hold=1;
	}	
//--------------------------------------End------------------------------------------------------------------//


	if($_REQUEST['index']!='' && isset($_REQUEST['index']))

	{

		$param="index=".$_REQUEST['index'];
		$searchSql.=" and username like'".$_REQUEST['index']."%'";
		$TEMP_hold=1;
	
    	}
	if($TEMP_hold == 0) 
	{
		$searchSql.=" ORDER BY siteuserId  DESC";

 	}
// echo $searchSql;
		$searchSql=$searchSql." limit $page,$limit";
		$searchquery=mysql_query($searchSql) or die('error1'.mysql_error());


//////////////////////////////update///////////////////////////

if(isset($_REQUEST['submit1']))
	{
	$update_query_user=" UPDATE ".SITEUSERS." SET 
		`fName`='".$_POST['ufname']."',
		`lName`='".$_POST['ulname']."',
		`phone`='".$_POST['phno']."',
		`company`='".$_POST['company']."',
		`registrationDate`='".$_POST['regdate']."',
		`status`='".$_POST['status']."'
		WHERE `siteuserId`='".$_REQUEST['id']."'";
		$update_plan_query1=mysql_query($update_query_user);
	
		echo '<script> window.location="advatisor.php?updt=1"</script>';

	}
	
?>

	  

 <table width="100%" border="0" cellspacing="0" cellpadding="3"  style="border:1px solid #666666">

<tr><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td></tr>

<tr>
	<td>

	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr style="display:" id="editWin">
			<td colspan='2' id="ShowMsg"></td>	
		</tr>
		<tr>
			<td colspan='2' style="color:#FF0000"><?php 	
			if(isset($_GET['blk']) && $_GET['blk']==1)	
				{		
					echo $msg1="Value Blocked/Unblocked Successfully!!!";		
				}
			
			if(isset($_GET['dlt']) && $_GET['dlt']==1)
			
				{
				
				echo $msg1="Value Deleted Successfully!!!";
				
				}
		
		?></td>
		
		</tr>
		<tr> 
		
			<td height="15" colspan="2" align="center" style="color:#000000;font-size:12px;"><font color="#000000"><strong>ADVERTISOR MANAGEMENT</strong></font> 
			
		</tr>
		
		<tr><td colspan="2">
	
	<?php
	if(isset($_REQUEST['action']))
	{
	$editquery=mysql_query("SELECT * FROM ".SITEUSERS." WHERE siteuserId='".$_REQUEST['id']."'");
	
	?>
	<fieldset>
	
	<?php while($fetch=mysql_fetch_array($editquery))
	
			{
		?>
		<legend class="LEGEND"><?php echo ucfirst($fetch['fName']); ?>'s Details</legend>
		<form name="edit" action="" method="POST" onsubmit="" >
	
	<table width="100%" border="0" align="left" cellspacing="5">
		<tr>
			<td id="admin_text">&nbsp;</td>
			<td >&nbsp;</td>
			<td align="right">&nbsp;</td>
		</tr>
		<tr>
			<td id="admin_text">Email</td>
			<td>:: </td>
			<td><?php echo $fetch['email'];?></td>
		</tr>
	
	
		<tr>
			<td id="admin_text">User Name </td>
			<td>::</td>
			<td><?php echo $fetch['username'];?></td>
		</tr>
	
			<tr>
			<td id="admin_text"> First Name </td>
			<td>::</td>
			<td><input name="ufname" type="text" value="<?php echo $fetch['fName'];?>" size="40"  /></td>
		</tr>		<tr>
			<td id="admin_text"> Last Name </td>
			<td>::</td>
			<td><input name="ulname" type="text" value="<?php echo $fetch['lName'];?>" size="40"  /></td>
		</tr>
	
		<tr>
			<td id="admin_text">Phone </td>
			<td>::</td>
			<td><input type="text" name="phno" value="<?php echo $fetch['phone'];?>" size="40" ></td>
		</tr>
		<tr>
			<td id="admin_text">Company Name </td>
			<td>::</td>
			<td><input type="text" name="company" value="<?php echo $fetch['company'];?>" size="40" /></td>
		</tr>
			
		
		<tr>
			<td id="admin_text">Registration Date </td>
			<td>::</td>
			<td><input type="text" name="regdate" value="<?php echo $fetch['registrationDate'];?>" size="40" /></td>
		</tr>
		<tr>AND userType='A'
			<td id="admin_text">User Type </td>
			<td>::</td>
			<td><input type="text" name="type" value="<?php if($fetch['userType']=='A'){echo "Advertisor";} elseif ($fetch['userType']=='P'){echo "Publisher";} elseif ($fetch['userType']=='B'){echo "Both";}?>" size="40"  readonly="true"/></td>
		</tr>
	
			
		<tr>
			<td id="admin_text">Status</td>
			<td>::</td>
			<td>
			Active
			
			<input type="radio" name="status" <?php if($fetch['status']=='Y'){?> checked="checked" <?php } ?> value="Y" style="border:0px;">
			
			&nbsp;&nbsp;Inactive
			
			<input type="radio" name="status" <?php if($fetch['status']=='N'){?> checked="checked" <?php } ?> value="N" style="border:0px;" >
			&nbsp;&nbsp;Painding
			
			<input type="radio" name="status" <?php if($fetch['status']=='P'){?> checked="checked" <?php } ?> value="P" style="border:0px;" >
			&nbsp;&nbsp;Blocked
			
			<input type="radio" name="status" <?php if($fetch['status']=='B'){?> checked="checked" <?php } ?> value="B" style="border:0px;" >
			
			</td>
		</tr>
		<tr>
			<td colspan="3" align="right"></td>
		</tr>
	
		<?php } ?>
	
		<tr>
			<td colspan="3" align="middle"><input type="submit" name="submit1" value="Update" />
		&nbsp;
		<input type="button" value="Close" name="close_frm" id="close_frm" onclick="window.location='advatisor.php';" /></td>
		</tr>
	</table>
	
	</form>
	
	</fieldset>
	
	<?php }?>
	
	</td></tr>
	<tr>
	
	<td height="15" colspan="" align="center" style="color:#000000;font-size:12px;"><p><strong style="font-weight: 400">Click on the alphabets to browse </strong>User Name<strong style="font-weight: 400"><br>&nbsp;</strong></p><?php include_once("search_alphabets.php");?></td>
	
	</tr>
	
</table>
<br />
<a href="advatisor.php" style="color:#000000;font-size:12px;">View All</a>
<br />  <table width="100%" border="0" cellspacing="0" cellpadding="3" class="tabbod" bgcolor="#F3F3F3">

    <form name="admin_user" action="advatisor.php" method="post">

    <tr>

      <td colspan="9">
		<table>
			<tr>
				<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Search By</font></td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td class="SMALL">Username:<input type="text" name="user" value="<?php echo $_POST['user'];?>"/></td>
				<td class="SMALL"> Email:<input type="text" name="email" value="<?php echo $_POST['email'];?>"/></td>
				<td class="SMALL"> User Status:<select name="selectstatus" class="SMALL" >
						<option value="" selected="selected">User Status </option>
						<option value="Y"  <?php if($statuetype == "Y") echo 'selected'; ?>>Active</option>
						<option value="N"  <?php if($statustype == "N") echo 'selected'; ?>>Inactive</option>
						<option value="P" <?php if($statustype == "P") echo 'selected'; ?>>Pending</option>
						<option value="B" <?php if($statustype == "B") echo 'selected'; ?>>Block</option>
					    </select>
				</td>
				<td><input type="submit" name="search" value="Search" /></td>
			</tr>
		</table>
	</td>
	
    </tr></form>

    <?php

  if(mysql_num_rows($searchquery)>0)

  {
  ?><form name="form_admin_management" action="" method="post">

    <tr bgcolor="#6F8DBC">

	<td colspan="2" style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>
	<td width="16%" style="color:#ffffff;font-size:12px;"><strong>User Name </strong></td>
	<td style="color:#ffffff;font-size:12px;"><strong>Email Address </strong></td>
	<td width="13%" align="center" style="color:#ffffff;font-size:12px;"><strong>Type</strong></td>
	<td width="9%" align="center" style="color:#ffffff;font-size:12px;"><strong>Details</strong></td>
	<td width="10%" align="center" style="color:#ffffff;font-size:12px;"><strong>Status</strong></td>
	<td width="7%" align="center" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>
	<td width="5%" align="center" style="color:#ffffff;font-size:12px;">&nbsp;</td>
    </tr>

    <?php 

  $count=0;
  $sno=1;
  $loop=0;
  while($searcharray=mysql_fetch_array($searchquery))
	{
	
			$loop++;
			if($loop == 1)
			$bgcolor = "#F0F0FF";
			else 
			$bgcolor = "#CCCCFF";
	
	?>
	
	<tr bgcolor="<?php echo $bgcolor; ?>">
	
			<td colspan="2" style="color:#000000;font-size:12px;"><strong><?php echo $sno+$_GET['page'];?></strong></td>
			<td style="color:#000000;font-size:12px;"><?php echo ucfirst($searcharray['username']); ?></td>
			<td style="color:#000000;font-size:12px;"><a href="mailto:<?php echo $searcharray['email'];?>" ><?php echo $searcharray['email']; ?></a> </td>
			<td align="center"><strong><?php if($searcharray['userType']=='A'){echo "Advertisor";} elseif ($searcharray['userType']=='P'){echo "Publisher";} elseif ($searcharray['userType']=='B'){echo "Advertiser as well as Publisher";}?></strong></td>
			<td align="center"><a href="advatisor.php?action=edit&id=<?php echo $searcharray['siteuserId'];?>" ><img src="images/edit_icon.gif" border="0"/></a></td>
			<td align="center"><strong> <?php if($searcharray['status']=='Y')
										{
											echo "Active";
										}
									if($searcharray['status']=='N')
										{
											echo "In Active";
										}
									if($searcharray['status']=='P')
										{
											echo "Pending";
										}
									if($searcharray['status']=='B')
										{
											echo "Blocked";
										}
										
										?>
				</strong></td>
	
			<td align="center"><input type="checkbox" name="del[]" value="<?php echo $searcharray['siteuserId'];?>"></td>
			
			<td align="center">&nbsp;</td>
	</tr>
	
    <?php 
  $count++;
  $sno++;
 		 if($loop == 2)
			{
			$loop = 0;
			}	
 }
		  
 ?>
    <tr>

      <td colspan="5">&nbsp;</td>

      <td colspan="5" align="right"><input type="hidden" name="count_update" value="<?php echo $count; ?>">

          <input type="submit" name="Submit" value="Update"></td>
    </tr>

    <tr>

      <td colspan="10" align="center" style="color:#FF0000"><?php echo paging($searchSql,$page,$limit,'',$param);?></td>
    </tr>

    <?php
}
else
{
?>

<tr bgcolor="#6F8DBC">

      <td width="2%" style="color:#ffffff;font-size:12px;">&nbsp;</td>

	  <td width="7%" align="center" style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>

	  <td width="16%" style="color:#ffffff;font-size:12px;"><strong>User  Name </strong></td>

	  <td style="color:#ffffff;font-size:12px;"><strong>Email Address </strong></td>

      <td width="9%" align="center" style="color:#ffffff;font-size:12px;"><strong>Details</strong></td>

      <td width="10%" align="center" style="color:#ffffff;font-size:12px;"><strong>Status</strong></td>

      <td width="7%" align="center" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>

      <td width="5%" align="center" style="color:#ffffff;font-size:12px;">&nbsp;</td>
    </tr>

    <tr>

      <td colspan="11" align="center" valign="middle" height="96"><strong><font color="#FF0000">No data available!</font></strong></td>
    </tr>

    <?php
  }
  ?></form>

  </table>

  </td></tr></table>

<?php 

include("foot.php");?>
